#!/usr/bin/python
# author dennis
# 2022年06月14日
# !/usr/bin/python
# author dennis
# 2022年06月14日
import time
import multiprocessing
import os


def coding():
    print("coding父进程>>>%d" % os.getppid())
    print("coding>>>%d" % os.getpid())
    for i in range(3):
        print("coding...")
        time.sleep(0.2)


def music():
    print("music父进程>>>%d" % os.getppid())
    print("music>>>%d" % os.getpid())
    for i in range(3):
        print("music...")
        time.sleep(0.2)


# 进程执行带有参数的任务
def coding1(num, name):
    for i in range(num):
        print(name)
        print("coding1...")
        time.sleep(0.2)


def play(count):
    for i in range(count):
        print("play...")
        time.sleep(0.2)


if __name__ == '__main__':
    print("主进程>>>%d" % os.getpid())
    # 通过进程类创建进程对象
    coding_process = multiprocessing.Process(target=coding)
    music_process = multiprocessing.Process(target=music)
    # coding1_process = multiprocessing.Process(target=coding1, args=(6,"传智"))
    # play_process = multiprocessing.Process(target=play, kwargs={"count": 5})
    # 启动进程
    coding_process.start()
    music_process.start()
    # coding1_process.start()
    # play_process.start()
